/*
 * AfterSaleProgressView.java
 * business
 *
 * Created by ChenTao on 2017/2/21.
 *
 * Copyright (c) 2017年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.utils.UIUtils;

import java.util.List;

/** 售后进度/订单进度 */
public class AfterSaleProgressView extends LinearLayout {
    private View mViewLeft;
    private View mViewCircle;
    private View mViewRight;
    private TextView mTvName;

    public AfterSaleProgressView(Context context) {
        this(context, null);
    }

    public AfterSaleProgressView(Context context, AttributeSet attrs) {
        super(context, attrs);

        View view = View.inflate(context, R.layout.item_order_progress, this);

        mViewLeft = view.findViewById(R.id.view_left);
        mViewCircle = view.findViewById(R.id.view_circle);
        mViewRight = view.findViewById(R.id.view_right);
        mTvName = (TextView) view.findViewById(R.id.tv_name);
    }

    public void setData(String status, int i, List<String> list) {
        int size = list.size();

        int index = list.indexOf(status); //此状态所处的位置

        //与此view所在的位置比较
        if (index > i) {
            mViewCircle.setSelected(true);
            setLineSelect(mViewLeft, true);
            setLineSelect(mViewRight, true);
        } else if (index == i) {
            mViewCircle.setSelected(true);
            setLineSelect(mViewLeft, true);
            setLineSelect(mViewRight, false);
        } else {
            mViewCircle.setSelected(false);
            setLineSelect(mViewLeft, false);
            setLineSelect(mViewRight, false);
        }

        //是否是首位
        mViewLeft.setVisibility(i == 0 ? INVISIBLE : VISIBLE);
        //是否是末尾
        mViewRight.setVisibility(i == size - 1 ? INVISIBLE : VISIBLE);

        mTvName.setText(list.get(i));
    }

    void setLineSelect(View view, boolean b) {

        if (b) {
            view.setBackgroundColor(UIUtils.getColor(R.color.colorSelector));
        } else {
            view.setBackgroundColor(UIUtils.getColor(R.color.text_hint_color));
        }
    }
}
